package com.loutick.basicforapp.service.impl;

import javax.annotation.Resource;  

import org.springframework.stereotype.Service;  
import org.springframework.transaction.annotation.Transactional;
  
import com.loutick.basicforapp.dao.*;
import com.loutick.basicforapp.entity.*;
import com.loutick.basicforapp.service.*; 
  
@Service("userService")   
@Transactional
public class UserServiceImpl implements IUserService {  
    @Resource  
    private TUserMapper userDao;

	public TUser getUserById(int userId) {
		return this.userDao.selectByPrimaryKey(userId);
	}
	
	/**
	 * 根据usid和channel 查找用户，如果没有就插入新的，有就返回旧的
	 */
	public int getUserByChannel(TUser tuser) {
		
		TUser user = this.userDao.selectByChannel(tuser) ;
		if(user!=null)
			return user.getUserid();
		else
			return this.userDao.insert(tuser);
		
		
	}

	public int registerUser(TUser tuser) {
		return this.userDao.insertSelective(tuser);
	}

	public TUser selectByPhoneNumber(String phoneNumber) {
		return this.userDao.selectByPhoneNumber(phoneNumber);
	}

	public int updateByPrimaryKey(TUser record) {
		
		return this.userDao.updateByPrimaryKeySelective(record);
	}  
	
    
}
